var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("GlobalUserData"),
s = t("HallConstant"),
l = t("HallScene"),
c = t("BroadCastMessage"),
d = t("Util"),
h = t("WXSDK"),
p = t("Global"),
u = t("BaseStorage"),
f = t("BonusUtil"),
m = t("ReceiveAward"),
_ = cc._decorator,
y = _.ccclass,
g = _.property,
v = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.coinCountText = null,
        e.coinCount = 0,
        e.maxAward = 1800,
        e.progressBar = null,
        e.timeStep = 0,
        e.step = 0,
        e.stepCount = 0,
        e.value = 3,
        e.awardPrefab = null,
        e.perValue = null,
        e.icon = null,
        e.coinPrefab = null,
        e.proObj = {
            a: 0
        },
        e.valueObj = {
            a: 0
        },
        e.action = !0,
        e.getValue = 0,
        e.receiveAward = function() {
            if (null == r.default.popup) {
                if (this.unschedule(this.receiveAward), 0 != this.valueObj.a) {
                    if (c.default.getInstance().SendMessage(s.Broadcast_Func.Audio, s.Audio_ID.btn_click), this.coinCount < this.maxAward && this.valueObj.a < 50) {
                        c.default.getInstance().SendMessage(s.Broadcast_Func.Audio, s.Audio_ID.get_gold);
                        var t = cc.find("Canvas").getChildByName("frame_gold");
                        return h.default.getIntance().expt_GetGold(this.coinCount),
                        r.default.saveGoldData(!0, this.coinCount),
                        cc.find("Canvas").getComponent(l.default).onSetOwnGold(!0),
                        f.default.action(this.icon, t, this.node, this.coinPrefab),
                        this.coinCount = 0,
                        this.getValue = 0,
                        void this.refresh()
                    }
                    if (!r.default.isGiftRushShow) {
                        u.BaseStorage.setString("CoinAwardShow", "Dshow");
                        var e = cc.instantiate(this.awardPrefab);
                        this.getValue = this.coinCount;
                        var o = [{
                            tag: p.BonusType.Coin,
                            icon: this.icon,
                            value: this.coinCount
                        }];
                        e.getComponent(m.default).init(o, this.refresh.bind(this), !1, p.VideoTab.dim10),
                        e.parent = cc.find("Canvas")
                    }
                }
            } else this.schedule(this.receiveAward, 1)
        },
        e.refreshTime = function() {
            var t = this; (this.timeStep = this.getTime()) && (this.timeStep = this.getTime(), this.step++);
            var e = this.step / 4;
            cc.tween(this.proObj).to(.5, {
                a: e
            }).call(function() {
                if (4 == t.step) {
                    if (t.perValue) {
                        t.perValue.active = !0;
                        var e = cc.v3(t.perValue.x, 35);
                        cc.tween(t.perValue).to(.5, {
                            position: e
                        }).call(function() {
                            t.perValue.y = 17,
                            t.perValue.active = !1
                        }).start()
                    }
                    t.step = 0,
                    cc.tween(t.proObj).to(.5, {
                        a: 0
                    }).start(),
                    t.stepCount++,
                    t.refreshCoin(t.stepCount)
                }
            }).start()
        },
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {
        this.coinCountText = this.node.getChildByName("coinCount").getComponent(cc.Label),
        this.progressBar = this.node.getChildByName("progressBar").getComponent(cc.ProgressBar)
    },
    e.prototype.start = function() {
        this.perValue.getComponent(cc.Label).string = "+" + this.value.toString(),
        this.perValue.active = !1,
        this.schedule(this.refreshTime, 1),
        d.Util.event_dispatcher.register(this)
    },
    e.prototype.onDestroy = function() {
        d.Util.event_dispatcher.remove(this)
    },
    e.prototype.onEnable = function() {
        u.BaseStorage.getInt(p.BaseStorageKey.GoldAwardTime, 0) ? (this.stepCount = Math.floor(this.getTime() / 4), this.refreshCoin(this.stepCount)) : this.refreshStorageTime()
    },
    e.prototype.showAwardPanel = function() {
        this.receiveAward()
    },
    e.prototype.refresh = function() {
        r.default.saveSpareCoinData(this.coinCount - this.getValue),
        this.action = !0,
        this.schedule(this.refreshTime, 1),
        this.refreshStorageTime(),
        this.timeStep = 0,
        this.step = 0,
        this.stepCount = 0,
        this.proObj.a = 0,
        this.valueObj.a = 0,
        cc.tween(this.valueObj).to(.5, {
            a: r.default.spareCoin
        }).start()
    },
    e.prototype.refreshStorageTime = function() {
        u.BaseStorage.setInt(p.BaseStorageKey.GoldAwardTime, new Date().getTime())
    },
    e.prototype.refreshCoin = function(t) {
        d.Util.itemHighestLevel() >= 10 && (console.log("refresh"), this.maxAward = Math.ceil(Math.pow(d.Util.itemHighestLevel(), 3) / 300 / 4 * 2400), this.value = Math.ceil(Math.pow(d.Util.itemHighestLevel(), 3) / 300), this.perValue.getComponent(cc.Label).string = "+" + this.value.toString()),
        this.coinCount = (t * this.value > this.maxAward ? this.maxAward: t * this.value) + r.default.spareCoin,
        cc.tween(this.valueObj).to(.5, {
            a: this.coinCount
        }).start(),
        this.coinCount >= this.maxAward && (this.action = !1, this.unschedule(this.refreshTime), r.default.coinPopup && "show" == u.BaseStorage.getString("CoinAwardShow") && this.receiveAward && this.receiveAward(), this.coinCountText.string = "已满")
    },
    e.prototype.getTime = function() {
        return Math.round((new Date().getTime() - u.BaseStorage.getInt(p.BaseStorageKey.GoldAwardTime)) / 1e3)
    },
    e.prototype.update = function() {
        this.action && (this.progressBar.progress = this.proObj.a, this.coinCountText.string = d.Util.get_num_processed(this.valueObj.a))
    },
    a([g(cc.Float)], e.prototype, "value", void 0),
    a([g(cc.Prefab)], e.prototype, "awardPrefab", void 0),
    a([g(cc.Node)], e.prototype, "perValue", void 0),
    a([g(cc.SpriteFrame)], e.prototype, "icon", void 0),
    a([g(cc.Prefab)], e.prototype, "coinPrefab", void 0),
    a([y], e)
} (cc.Component);
o.default = v